package com.itheima.d_request_04;

import com.sun.prism.shader.Solid_TextureYV12_AlphaTest_Loader;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.beans.Encoder;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;

@WebServlet("/RequestServlet08")
//http://localhost:8080/day07/RequestServlet03?username=zhangsan&password=123
public class RequestServlet08 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//1
/*
        String username = request.getParameter("username");

        username = URLEncoder.encode(username, "ISO-8859-1");
        username = URLDecoder.decode(username, "UTF-8");

        System.out.println(username);
*/

//2

        String username = request.getParameter("username");
        byte[] bytes = username.getBytes("ISO-8859-1");
        username = new String(bytes,"UTF-8");
        System.out.println(username);

//3

      /*  request.setCharacterEncoding("utf-8");

        String username = request.getParameter("username");
        System.out.println(username);*/

    }
    }
